package com.sptpc.demo.controller;

import com.sptpc.demo.model.Category;
import com.sptpc.demo.model.Drink;
import com.sptpc.demo.service.ICategoryService;
import com.sptpc.demo.service.IDrinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class RouterController {
    @Autowired
    public IDrinkService drinkService;
    @Autowired
    public ICategoryService categoryService;

    // 首页（登录）路由
    @GetMapping("/")
    public String index() {
        return "manage/login";
    }

    // 后台首页路由
    @GetMapping("/manage/index")
    public String adminIndex() {
        return "manage/index";
    }

    // 后台欢迎页面路由
    @GetMapping("/manage/welcome")
    public String welcome() {
        return "manage/welcome";
    }

    //////////////////////////////////
    //           饮品管理            //
    //////////////////////////////////
    // 饮品管理首页路由
    @GetMapping("/menu/drink")
    public String drinkIndex() {
        return "drink/index";
    }


    // 饮品添加页路由
    @GetMapping("/drink/addform")
    public String drinkAddFrom() {
        return "drink/add";
    }

    // 饮品修改页路由
    // get /drink/updateform?id=13
    @GetMapping("/drink/updateform")
    public ModelAndView drinkUpdateFrom(@RequestParam Long id) {
        ModelAndView mv = new ModelAndView("drink/edit");
        Drink drink = drinkService.getDrinkById(id);

        mv.addObject("data", drink);
        return mv;
    }

    //////////////////////////////////
    //           分类管理            //
    //////////////////////////////////
    // 分类管理首页路由
    @GetMapping("/menu/category")
    public String categoryIndex() {
        return "category/index";
    }
//
    // 分类添加页路由
    @GetMapping("/category/addform")
    public String categoryAddFrom() {
        return "category/add";
    }

    // get /category/updateform?id=2
    @GetMapping("/category/updateform")
    public ModelAndView categoryUpdateFrom(@RequestParam Long id) {
        ModelAndView mv = new ModelAndView("category/edit");
        Category category = categoryService.getCategoryById(id);

        mv.addObject("data", category);
        return mv;
    }

    //学生管理首页路由
    @GetMapping("/menu/stu")
    public String studentIndex(){
        return "student/index";
    }

}
